//
//  TicketRepeatView.swift
//  ANOA
//
//  Created by 邱仙凯 on 2021/9/16.
//  Copyright © 2021 aowang. All rights reserved.
//  发票重复提醒页面

import UIKit
 
class TicketRepeatView:UIView {
   var contentV:UIView!
    var bg:UIView!
   var resultClosure:((String)->())?
   var arr = [String]()
   override init(frame: CGRect){
        super.init(frame: frame)
        setup()
   }
    lazy var attributes:[NSAttributedString.Key : NSObject] = {
        let paraph = NSMutableParagraphStyle()
        //将行间距设置为
        paraph.lineSpacing = 12
        //样式属性集合
        let titleAttributes = [NSAttributedString.Key.font:UIFont.systemFont(ofSize: 16),
                           NSAttributedString.Key.paragraphStyle: paraph]
        return titleAttributes
    }()
    var contentStr = "" {
        didSet {
            contentLab.attributedText = NSAttributedString(string: contentStr, attributes: attributes)
        }
    }
    
    lazy var titleLab:UILabel = {
       let v = UILabel()
        v.text = "当前发票重复"
        v.font = UIFont.systemFont(ofSize: 19)
        return v
    }()
    lazy var contentLab:UILabel = {
       let v = UILabel()
        v.numberOfLines = 0
        return v
    }()
    lazy var confirmBtn:UIButton = {
       let v = UIButton()
        v.layer.cornerRadius = 16
        v.layer.borderWidth = 1
        v.setTitle("确认", for: .normal)
        v.setTitleColor(.lightGray, for: .normal)
        v.layer.borderColor = UIColor.lightGray.cgColor
        return v
    }()
   func setup() {
       self.isUserInteractionEnabled = true
       let gr = UITapGestureRecognizer(target: self, action: #selector(close))
       gr.numberOfTapsRequired = 1
       bg = UIView(frame: CGRect(x:0,y: 0 ,width: KSGlobal.screenW,height: KSGlobal.screenH))
       bg.isUserInteractionEnabled = true
       bg.backgroundColor = UIColor.black.withAlphaComponent(0.6)
       addSubview(bg)
       bg.addGestureRecognizer(gr)
       
       contentV = UIView(frame: CGRect(x:20,y:(KSGlobal.screenH - 260)/2,width: KSGlobal.screenW - 40,height: 0))
        contentV.layer.cornerRadius = 5
        contentV.backgroundColor = .white
        addSubview(contentV)
    
    contentV.addSubview(titleLab)
    contentV.addSubview(contentLab)
    contentV.addSubview(confirmBtn)
    confirmBtn.addTarget(self, action: #selector(close), for: .touchUpInside)
    titleLab.snp.makeConstraints { make in
        make.top.equalTo(contentV).offset(40)
        make.centerX.equalTo(contentV)
    }
    contentLab.snp.makeConstraints { make in
        make.top.equalTo(titleLab.snp.bottom).offset(20)
        make.left.equalTo(contentV).offset(10)
        make.right.equalTo(contentV).offset(-10)
    }
    confirmBtn.snp.makeConstraints { make in
        make.top.equalTo(contentLab.snp.bottom).offset(20)
        make.centerX.equalTo(contentV)
        make.width.equalTo(100)
        make.height.equalTo(33)
     }
    
   }
 
   override func willMove(toSuperview newSuperview: UIView?) {
      
       if newSuperview.isSome {
           UIView.animate(withDuration: 0.05) { //  出现时
                self.contentV.ks_height =  260
           }
       }
       
   }

   @objc func close(){
       UIView.animate(withDuration: 0.05) {
           self.contentV.ks_height = 0
       }
       
       DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.05) {
           self.removeFromSuperview()
       }
       
       
   }
  
   
   required init?(coder: NSCoder) {
       fatalError("init(coder:) has not been implemented")
   }
   
}
